﻿using Microsoft.Xna.Framework;
using SomeGame.Actors.Components.State;

namespace SomeGame.Actors.Components.Mind {

	public class ZombieMind : ActorComponent {

	    public readonly ZombieStateMachine StateMachine; // Manipulated by the Mind, which than manipulates the other components.
	    private double ElapsedTime; // TODO: Remove this unless a 'script' type thing is used for setting up patrol.

		public ZombieMind(ZombieStateMachine stateMachine) {
			StateMachine = stateMachine;
		}

		public override void Update(GameTime gameTime, bool parallax) {
			/*
			 * This is a temporary 'script' to give the Zombie something to do.
			 */
			if (StateMachine.CurrentState != ZombieStateMachine.State.InPain
                && StateMachine.CurrentState != ZombieStateMachine.State.Dead
                && StateMachine.CurrentState != ZombieStateMachine.State.Dying
                && StateMachine.CurrentState != ZombieStateMachine.State.Gibbed
                && StateMachine.CurrentState != ZombieStateMachine.State.Goo) {
			    ElapsedTime += gameTime.ElapsedGameTime.TotalSeconds;
			    if (ElapsedTime > 6) {
			        switch (GameEngine.Random.Next(0, 3)) {
			            case 0:
			                StateMachine.SetCurrentState(ZombieStateMachine.State.Idle);
			                break;
                        case 1:
			            case 2:
			                StateMachine.SetCurrentState(ZombieStateMachine.State.Walking);
			                break;
			        }
			        ElapsedTime -= 6;
			    }
			}
			StateMachine.Update(gameTime, parallax);
		    if (StateMachine.CurrentState == ZombieStateMachine.State.InPain) {
		        ElapsedTime = 0; // Give him time to finish being in pain.
		    }
		}

	}

}